{include file="header" title="YunCMS后台管理系统" keywords="" description=""/}
<link rel="stylesheet" href="/static/common/editor/css/editormd.css"/>

<div class="content-page">

    <form class="am-g  am-form margin-top-buttom-20" data-am-validator enctype="multipart/form-data" method="post">
<!--
        <div class="am-form-group all-width">
            <div id="event"></div>
            <div>
                <button type="button" id="callBack">上传结果</button>
                <div id="fileResult"></div>
            </div>
        </div>-->
        <div class="am-form-group all-width">
            <label>标题</label>
            <input type="text" required name="content[title]" {notempty name="content" } value="{$content.title}" {/notempty}>
        </div>


        <div class="am-form-group all-width">
            <label>所属栏目</label>
            <select id="cate-parent-num" name="content[category_id]" maxlength="200" onchange="get_model_pro();" required>
                {volist name='cate' id='cate'}
                <option value="{$cate.category_id}" data-model="{$cate.model_id}" {notempty name="content" } {if condition="$content.category_id == $cate.category_id" } selected {/if} {/notempty}>{$cate.category_name}</option>
                {/volist}
            </select>
            <span class="am-form-caret"></span>
        </div>


        <div id="html_pro" class="html_pro_style">

        </div>

        <div class="am-form-group all-width">
            <div class="add-img-backgound">
                <label for="content-cover">内容封面:</label>
                <input class="inputfile-hide" type="file" name="uploadimages" id="content-cover" {notempty
                       name="content" } value="{$content.cover}" {/notempty}>
                <br><img class="button-text-left input-img-maxsize"
                         src="{notempty name='content'}{$content.cover|get_image_url=###}{/notempty}"
                         id="content-img"><label
                for="content-cover" class="add-img-btn">
                <div class="am-icon-plus-square am-icon-lg add-img-div"></div>
            </label><br>
            </div>
        </div>

        <div class="am-form-group all-width">
            <label>标签</label>
            <select id="cate-parent-num" name="content[tag_id]" maxlength="200" required>
                {volist name='tag' id='tag'}
                <option value="{$tag.tag_id}"  {notempty name="content" } {if condition="$content.tag_id == $tag.tag_id" } selected {/if} {/notempty}>{$tag.tag_name}</option>
                {/volist}
            </select>
            <span class="am-form-caret"></span>
        </div>

        <div class="am-form-group all-width">
            <label>简介</label>
            <textarea required name="content[intro]">{notempty name="content"} {$content.intro} {/notempty}</textarea>
            <div></div>
        </div>
        <div class="am-form-group all-width">
            <label>内容</label>
            <div class="editor-position-display">
                <div id="test-editormd">
                        <textarea required name="content[content]" style="display:none;" id="ts">{notempty name="content"
                            } {$content.content} {/notempty}</textarea>
                </div>
            </div>
        </div>

        <div class="am-form-group all-width">
            <label>SEO标题:</label>
            <input type="text" name="content[seo_title]" maxlength="200"
                    {notempty name="content"
                   } value="{$content.seo_title}" {/notempty}>
        </div>
        <div class="am-form-group all-width">
            <label>SEOurl</label>
            <input type="text" name="content[seo_url]" maxlength="200" minlength="3"
                    required {notempty name="content"
                   } value="{$content.seo_url}" {/notempty} />
        </div>
        <div class="am-form-group  all-width">
            <label>SEO关键字</label>
            <input type="text" name="content[seo_key]" maxlength="200"
                   {notempty name="content" } value="{$content.seo_key}" {/notempty} />
        </div>


        <!--<div class="am-form-group all-width">-->
        <!--<label for="content-seo-desc">SEO描述</label>-->
        <!--<textarea name="content[seo_desc]" id="content-seo-desc" maxlength="200"-->
        <!--placeholder="请输入SEO描述">{notempty name="content"-->
        <!--} {$content.seo_desc} {/notempty}</textarea>-->
        <!--</div>-->
        <!--<div class="am-form-group">-->
        <!--<label>阅读量</label>-->
        <!--<input type="text" disabled name="content[read_number]" {notempty name="content"-->
        <!--} value="{$content.read_number}" {/notempty}>-->
        <!--</div>-->
        {notempty name="content"} <input type="hidden" name="id" value="{$content.content_id}"> {/notempty}
        <div class="am-form-group  all-width">
            <button class="am-btn am-btn-primary am-radius " type="submit">提交</button>
        </div>
    </form>


</div>
</div>
<script src="/static/common/jquery/jquery.min.js"></script>
<script src="/static/common/editor/editormd.js"></script>
<script type="text/javascript">
    //    调用编辑器
    var testEditor;
    $(function () {
        testEditor = editormd("test-editormd", {
            width: "1399px",
            height: 640,
            syncScrolling: "single",
            path: "/static/common/editor/lib/"

        });
    });
</script>
{include file="footer" /}


<script type="text/javascript">

    /* alert("{$action_name}");*/

    $(function () {
        var model_id = $("#cate-parent-num").find("option:selected").attr("data-model");

        model_pro_info(model_id);
    });

    function get_model_pro() {
        var model_id = $("#cate-parent-num option:checked").data("model");
        $('#html_pro').html('');
        model_pro_info(model_id);
    }

    function model_pro_info(model_id) {
        var urls = "{:url('admin/content/get_module_pro')}";
        var article_id;
        if ($("input[name='id']").val()) {
            article_id = $("input[name='id']").val();
        } else {
            article_id = 0;
        }
        $.ajax({
            url: urls,
            data: {
                model_id: model_id,
                type: 1,
                article_id: article_id
            },
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (datas) {
                if (datas['code'] == 1) {
                    if (datas['info'].length > 0) {
                       /* console.log(datas['info']);*/
                        var html_pro = get_model_pro_html(datas['info']);
                        $('#html_pro').html(html_pro);
                    }
                } else {
                    alert(datas['msg']);
                }
            },
            error: function () {
                alert("异常！");
            }
        });
    }

    //循环输出标签……
    function get_model_pro_html(data) {
        var str = '';
        for (var i = 0; i < data.length; i++) {
            if (data[i]['type'] === 'text') {
                str +='<div class="am-form-group all-width">';
                str += '<label>'+data[i]['pro_name']+'</label>';
                str += '<input type="text" name="pro['+data[i]['pro_key']+']" value="'+data[i]['value']+'" />';
                str +='</div>';
            }
            else if (data[i]['type'] == 'file') {
                //str += '<div class="am-form-group all-width">' + '<label>标题</label>' + '<input disabled type="text" value=' + data[i]['pro_name'] + '>' + '<label>字段名</label>' + '<input disabled type="text"  value="' + data[i]['pro_key'] + '">' + '</div>';
            } else if (data[i]['type'] == 'textarea') {
                str +='<div class="am-form-group all-width">';
                str+='<label for="content-seo-desc">'+data[i]['pro_name']+'</label>';
                str+='<textarea name="pro['+data[i]['pro_key']+']"  maxlength="200" >'+data[i]['value']+'</textarea>';
                str +='</div>';
            }
            else if (data[i]['type'] == 'select') {
                str +='<div class="am-form-group all-width">';
                var selectaa = data[i]['pro_value'];
                var selectbb = selectaa.split(',');
                str+='<label>'+data[i]['pro_name']+'</label>';
                str+='<select name="pro['+data[i]['pro_key']+']" required>';
                if (selectbb) {
                    for (var k = 0; k < selectbb.length; k++) {
                        var sel = selectbb[k].split('|');
                        str += '<option value="'+sel[1]+'"';
                        if(data[i]['value'] == sel[1]){
                            str += ' selected ';
                        }
                        str += '>'+sel[0]+'</option>';
                    }
                }
                str+='</select><span class="am-form-caret"></span>';
                str +='</div>';
            }
            else if (data[i]['type'] == 'radio') {
                str +='<div class="am-form-group all-width">';
                var radioaa = data[i]['pro_value'];
                var radiobb = radioaa.split(',');
                if (radiobb) {
                    for (var l = 0; l < radiobb.length; l++) {
                        var rad = radiobb[l].split('|');
                        str+='<label class="am-radio-inline"><input type="radio" data-am-ucheck name="pro['+data[i]['pro_key']+']" value="'+rad[1]+'" ';
                        if(data[i]['value'] == rad[1]){
                            str += ' checked ';
                        }
                        str+='>'+rad[0]+'</label>';
                    }
                }
            }
            else if (data[i]['type'] == 'checkbox') {
                console.log(data[i]);
                str +='<div class="am-form-group all-width">';
                str+='<label>'+data[i]['pro_name']+'</label><br>';
                var checkboxaa = data[i]['pro_value'];
                var checkboxbb = checkboxaa.split(',');
                if (checkboxbb) {
                    for (var l = 0; l < checkboxbb.length; l++) {
                        var che = checkboxbb[l].split('|');
                        str+='<label class="am-checkbox-inline" onclick="getcheckvalue('+data[i]['model_properties_id']+');"><input type="checkbox" data-am-ucheck class="checkboxval'+data[i]['model_properties_id']+'""  value="'+che[1]+'"';
                        var check = data[i]['value'].split(',');
                        if(data[i]['value'].toString().indexOf(che[1]) > -1) {
                        //if(data[i]['value'] == che[1]){
                            str += ' checked ';
                        }
                        str+='>'+che[0]+'</label>';
                    }
                }
                str +='</div>';
                str += '<input type="hidden" id="checkboxval'+data[i]['model_properties_id']+'" name="pro['+data[i]['pro_key']+']" value="'+data[i]['value']+'" ></div>';
            }
        }
        return str;
    }
    function getcheckvalue(id) {
        var checkdata = [];
        function check() {
            $('.checkboxval'+id+':checked').each(function () {
                checkdata.push($(this).val());
            });
            $('#checkboxval'+id).val(checkdata);
        }
        check();
       /* $(':checkbox').click(function () {
            check();
        });*/
    }
</script>
